import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

from langchain_ollama import OllamaEmbeddings
from langchain.chains import RetrievalQA
try:
    # 使用Ollama的嵌入模型
    embeddings_model = OllamaEmbeddings(
        base_url='http://192.168.2.208:11434',
        model="nomic-embed-text")
    embeddings = embeddings_model.embed_documents(
        [
            "Hi there!",
            "Oh, hello!",
            "What's your name?",
            "My friends call me World",
            "Hello World!"
        ]
    )
    print(len(embeddings))
    print (len(embeddings[1]))

    embedded_query = embeddings_model.embed_query("What was the name mentioned in the conversation?")
    print(embedded_query[:5])

except Exception as e:
    error_msg = f"执行错误: {e}"
    print(error_msg)  # Continue 会捕获控制台输出